package com.then.architecture.data.repository;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.then.architecture.AppExecutors;
import com.then.architecture.data.api.ApiResponse;

/**
 * Created by 42524 on 2018/1/23.
 */

public abstract class SimpleNetBoundResource<ResultType, RequestType> extends BoundResource<ResultType, RequestType> {

     protected RequestType item;

    public SimpleNetBoundResource(AppExecutors appExecutors) {
        super(appExecutors);
    }

    @Override
    protected void saveCallResult(@NonNull RequestType item) {
           this.item=item;
    }

    @Override
    protected boolean shouldFetch(@Nullable ResultType data) {
        return true;
    }

    @NonNull
    @Override
    protected LiveData<ResultType> loadFromDb() {
      MutableLiveData data=new MutableLiveData();
      data.postValue(item);
      return data;
    }

    protected abstract LiveData<ApiResponse<RequestType>> createCall();


}
